﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Domain
{
    public class ProductsRepository
    {
        public static IEnumerable<Product> getProducts(string categoryId = null)
        {
            Category c1 = new Category { Id = 1, Name = "Category 1" };
            Category c2 = new Category { Id = 2, Name = "Category 2" };

            List<Product> products = new List<Product>();

            Random r = new Random();

            for (int i = 1; i <= 100; i++)
            {
                if (i % 2 == 0)
                {
                    products.Add(new Product
                    {
                        Id = i,
                        Name = "Product " + i,
                        Category = c1,
                        Release = DateTime.Now.AddDays(i),
                        Price = (1 + r.NextDouble()) * 100,
                        Quantity = r.Next(50)
                    });
                }
                else
                {
                    products.Add(new Product
                    {
                        Id = i,
                        Name = "Product " + i,
                        Category = c2,
                        Release = DateTime.Now.AddDays(i),
                        Price = (1 + r.NextDouble()) * 100,
                        Quantity = r.Next(50)
                    });
                }
            }

            if (categoryId != null)
            {
                products = products.Where(p => p.Category.Id == int.Parse(categoryId)).ToList();
            }

            return products;
        }

        public static object getProduct(int id)
        {
            Category c1 = new Category { Id = 1, Name = "Category 1" };
            Category c2 = new Category { Id = 2, Name = "Category 2" };
            var r = new Random();
            return new Product() { Id = id, Category = (id % 2 == 0) ? c1 : c2, Name = "Product " + id, Price = (1 + r.NextDouble()) * 100, Quantity = r.Next(50) };
        }
    }
}